import 'package:flutter/material.dart';

/// ntt 主题色 Switch
class NttSwitch extends StatelessWidget {
  final double? width;
  final double? height;

  /// 默认值
  final bool value;

  /// 值改变回调
  final Function(bool)? onChanged;

  /// 激活时边框颜色
  final Color? activeFrameColor;

  /// 未激活时边框颜色
  final Color? inactiveFrameColor;

  /// 激活时圆点颜色
  final Color? activeColor;

  /// 未激活时圆点颜色
  final Color? inactiveColor;

  /// 激活时轨道颜色 也就是背景颜色
  final Color? activeTrackColor;

  /// 未激活时轨道颜色 也就是背景颜色
  final Color? inactiveTrackColor;

  const NttSwitch(
    this.value,
    this.onChanged, {
    super.key,
    this.width,
    this.height,
    this.activeFrameColor,
    this.inactiveFrameColor,
    this.activeColor,
    this.inactiveColor,
    this.activeTrackColor,
    this.inactiveTrackColor,
  });

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: width,
      height: height,
      child: FittedBox(
        fit: BoxFit.contain,
        child: Switch(
          value: value,
          onChanged: onChanged,

          /// 修改Switch边框颜色
          trackOutlineColor: MaterialStateProperty.resolveWith(
            (final Set<MaterialState> states) {
              if (states.contains(MaterialState.selected)) {
                /// 开启时边框颜色
                return activeFrameColor ?? const Color(0xffFDAD30);
              }

              /// 关闭时边框颜色
              return inactiveFrameColor ?? const Color(0xffDBDCE0);
            },
          ),
          activeColor: activeColor ?? const Color(0xffFDAD30),
          activeTrackColor: activeTrackColor ?? Colors.white,
          inactiveThumbColor: inactiveColor ?? const Color(0xffDBDCE0),
          inactiveTrackColor: inactiveTrackColor ?? Colors.white,
        ),
      ),
    );
  }
}
